package com.ruyiadmin.springboot.service_layer.implementations.business_implementations.module_management;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruyiadmin.springboot.common_infrastructure.models.SearchCondition;
import com.ruyiadmin.springboot.common_infrastructure.models.QueryResponseResult;
import com.ruyiadmin.springboot.entity_data_model.data_transformation_model.business_model.module_management.BizUserModuleDTO;
import com.ruyiadmin.springboot.entity_data_model.entity_model.business_model.module_management.BizUser;
import com.ruyiadmin.springboot.repository_layer.business_repositories.module_management.IBizUserRepository;
import com.ruyiadmin.springboot.service_layer.interfaces.business_interfaces.module_management.IBizUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 模块用户表 服务实现类
 * </p>
 *
 * @author RuYiAdmin
 * @since 2022-07-12
 */
@Service
@RequiredArgsConstructor
public class BizUserServiceImpl extends ServiceImpl<IBizUserRepository, BizUser> implements IBizUserService {

    //region 实现类私有属性

    private final IBizUserRepository bizUserRepository;

    //endregion

    //region 查询离态用户列表

    /**
     * <p>
     * 查询离态用户列表
     * </p>
     *
     * @param searchCondition 查询条件
     * @return 查询结果
     */
    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public QueryResponseResult<BizUserModuleDTO> queryUserNonModule(SearchCondition searchCondition) {
        QueryWrapper<BizUserModuleDTO> wrapper = new QueryWrapper<>();
        searchCondition.convertToQueryWrapper(wrapper);

        Page<BizUserModuleDTO> page = new Page<>(searchCondition.getPageIndex(), searchCondition.getPageSize());
        IPage<BizUserModuleDTO> records = this.bizUserRepository.queryUserNonModule(page, wrapper);

        return QueryResponseResult.success(records.getTotal(), records.getRecords());
    }

    //endregion

    //region 查询所有业务用户

    /**
     * <p>
     * 查询所有业务用户
     * </p>
     *
     * @return 业务用户集合
     */
    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public List<BizUser> queryAllBizUsers() {
        return this.bizUserRepository.queryAllBizUsers();
    }

    //endregion

}
